package master.ghrm.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Version;

import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

@Entity
public class PersonalDevelopmentPlan extends AbstractBaseEntity {

	private static final long serialVersionUID = 1L;

	public static final int LONG_TERM_GOAL_LENGTH = 1000;
	public static final int PDP_TEXT_LENGTH = 10000;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "pdp_id", unique = true, nullable = false)
	private Long pdpId = null;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "profile_id")
	@ForeignKey(name = "FKPDP_PROFILEID")
	private Profile profile;

	@Column(name = "from_date")
	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime fromDate;

	@Column(name = "to_date")
	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime toDate;

	@Column(name = "creation_date")
	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime creationDate;

	@Column(name = "text_content", length = PDP_TEXT_LENGTH)
	private String textContent;

	@Column(name = "long_term_goal", length = LONG_TERM_GOAL_LENGTH)
	private String longTermGoal;

	private Boolean approved;

	@Version
	private Long version;

	/**
	 * Default constructor, for persistence use only.
	 */
	public PersonalDevelopmentPlan() {
		approved = false;
	}

	/**
	 * Full constructor.
	 * 
	 * @param aProfile user this PDP belongs to.
	 * @param from starting date.
	 * @param to end date.
	 * @param created creation date.
	 * @param aTextContent content
	 * @param aLongTermGoal long term goal.
	 */
	public PersonalDevelopmentPlan(Profile aProfile, DateTime from, DateTime to, DateTime created, String aTextContent,
			String aLongTermGoal) {
		this.profile = aProfile;
		this.fromDate = from;
		this.toDate = to;
		this.creationDate = created;
		this.textContent = aTextContent;
		this.longTermGoal = aLongTermGoal;
		this.approved = false;
	}

	/**
	 * @return ID.
	 */
	public Long getPdpId() {
		return this.pdpId;
	}

	/**
	 * For persistence use only.
	 * 
	 * @param aPdpId ID.
	 */
	public void setPdpId(Long aPdpId) {
		this.pdpId = aPdpId;
	}

	/**
	 * @return owner.
	 */
	public Profile getProfile() {
		return this.profile;
	}

	/**
	 * @param profile owner.
	 */
	public void setProfile(Profile aProfile) {
		this.profile = aProfile;
	}

	/**
	 * @return start date.
	 */
	public DateTime getFromDate() {
		return this.fromDate;
	}

	/**
	 * @param from start date.
	 */
	public void setFromDate(DateTime from) {
		this.fromDate = from;
	}

	/**
	 * @return end date.
	 */
	public DateTime getToDate() {
		return this.toDate;
	}

	/**
	 * @param to end date.
	 */
	public void setToDate(DateTime to) {
		this.toDate = to;
	}

	/**
	 * @return creation date.
	 */
	public DateTime getCreationDate() {
		return this.creationDate;
	}

	/**
	 * @param created creation date.
	 */
	public void setCreationDate(DateTime created) {
		this.creationDate = created;
	}

	/**
	 * @return content
	 */
	public String getTextContent() {
		return this.textContent;
	}

	/**
	 * @param content content.
	 */
	public void setTextContent(String content) {
		this.textContent = content;
	}

	/**
	 * @return long term goal.
	 */
	public String getLongTermGoal() {
		return this.longTermGoal;
	}

	/**
	 * @param aLongTermGoal long term goal, up to 1000 chars.
	 */
	public void setLongTermGoal(String aLongTermGoal) {
		this.longTermGoal = aLongTermGoal;
	}

	public Boolean getApproved() {
		return approved;
	}

	/**
	 * @param isApproved
	 */
	public void setApproved(Boolean isApproved) {
		this.approved = isApproved;
	}

	/**
	 * For persistence use only.
	 * 
	 * @return entity version.
	 */
	Long getVersion() {
		return this.version;
	}

	/**
	 * For persistence use only.
	 * 
	 * @param aVersion entity version.
	 */
	void setVersion(Long aVersion) {
		this.version = aVersion;
	}

	/**
	 * @see com.levi9.hrm.model.base.AbstractBaseEntity#getExcludedAttributes()
	 */
	@Override
	protected String[] getExcludedAttributes() {
		return new String[] {};
	}

}
